package com.xmall.controller.wx;

import com.xmall.bean.vo.*;
import com.xmall.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Connor
 * @ClassName: CouponController
 * @PackageName: com.xmall.controller.wx
 * @date 2020/12/09
 * @Version 1.0
 */
@RestController("wxCouponController")
@RequestMapping("wx/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @GetMapping("list")
    public BaseRespVo listMallCoupon(Integer page, Integer size) {
        CouponVO<CouponMallVO> couponVO = couponService.listMallCoupon(page, size);
        return BaseRespVo.ok(couponVO);
    }

    @GetMapping("mylist")
    public BaseRespVo listUserCoupon(Integer page, Integer size, Short status) {
        CouponVO<CouponUserVO> couponVO = couponService.listUserCoupon(page, size, status);
        return BaseRespVo.ok(couponVO);
    }

    @GetMapping("selectlist")
    public BaseRespVo listSelectiveCoupon(Integer cartId, Integer grouponRulesId) {
        List<CouponUserVO> couponUserVOS = couponService.listSelectiveCoupon(cartId, grouponRulesId);
        return BaseRespVo.ok(couponUserVOS);
    }

    @PostMapping("receive")
    public BaseCouponRespVO receiveCoupon(@RequestBody Map<String, Integer> map) {
        BaseCouponRespVO baseCouponRespVO = couponService.receiveCoupon(map);
        return baseCouponRespVO;
    }

    @PostMapping("exchange")
    public BaseCouponRespVO exchangeCoupon(@RequestBody Map<String, String> map) {
        BaseCouponRespVO baseCouponRespVO = couponService.exchangeCoupon(map);
        return baseCouponRespVO;
    }
}
